<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>尾款详情</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
    <style type="text/css">
        thead th, tbody td {
            padding-left: 8px !important;
            padding-right: 8px !important;
        }

        .file-name {
            margin-left: 110px;
            margin-top: 10px;
        }

        .file-name a {
            text-decoration: underline;
            color: red;
        }

        .upload-desc {
            margin-left: 110px;
            margin-top: 10px;
            color: #999;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" action="${ctx}/moneyManagement/tailParagraph/tailParagraphList.do"
                              id="myForm" method="post">
                            <input type="hidden" name="memberId" id="memberId" value="${memberId}"/>
                            <input type="hidden" name="businessId" id="businessId" value="${businessId}"/>
                        </form>
                        <div class="my-act-list-content">
                            <div class="cl">
                                <table class="layui-table">
                                    <tbody>
                                    <c:forEach var="wao" items="${list}" varStatus="st">
                                        <tr>
                                            <td colspan="6">
                                                <div class="tc">

                                                    <div class="layui-input-inline" style="font-size:18px;">
                                                        <c:choose>
                                                            <c:when test="${wao.progress == 1}">
                                                                <font color="green">提交申请</font>
                                                            </c:when>
                                                            <c:when test="${wao.progress == 2}">
                                                                <font
                                                                        <c:if test="${wao.state == 1}">color="green"</c:if>
                                                                        <c:if test="${wao.state == 0}">color="red"</c:if>
                                                                >客服处理</font>

                                                            </c:when>
                                                            <c:when test="${wao.progress == 3}">
                                                                <font
                                                                        <c:if test="${wao.state == 1}">color="green"</c:if>
                                                                        <c:if test="${wao.state == 0}">color="red"</c:if>
                                                                >客户确认</font>

                                                            </c:when>
                                                            <c:when test="${wao.progress == 4}">
                                                                <font
                                                                        <c:if test="${wao.state == 1}">color="green"</c:if>
                                                                        <c:if test="${wao.state == 0}">color="red"</c:if>
                                                                >财务打款</font>
                                                            </c:when>
                                                        </c:choose>
                                                    </div>
                                                </div>
                                                <c:if test="${wao.state != 3}">
                                                    <div class="tc"></div>
                                                    <div class="tc">
                                                        <div class="layui-input-inline">
                                                            <fmt:formatDate value="${wao.createDate}"
                                                                            pattern="yyyy-MM-dd HH:mm:ss"/>
                                                        </div>
                                                    </div>
                                                    <c:if test="${wao.progress == 1}">
                                                        <div class="tc">
                                                            <label class="search-form-lable"><strong>备注：</strong></label>
                                                            <div class="layui-input-inline">
                                                                    ${wao.noteMessage}
                                                            </div>
                                                        </div>
                                                        <c:if test="${wao.accessoryUrl !=null && wao.accessoryUrl!=''}">
                                                            <div class="tc">
                                                                <label class="search-form-lable"><strong>附件：</strong></label>
                                                                <div class="layui-input-inline">
                                                                    <a target="_blank" style="color: green" href="${wao.accessoryUrl}">下载附件</a>
                                                                </div>
                                                            </div>
                                                        </c:if>
                                                    </c:if>
                                                    <c:if test="${wao.progress != 1}">
                                                        <div class="tc">
                                                            <label class="search-form-lable"><strong>结果：</strong></label>
                                                            <span class="layui-input-inline">

                                                        <c:choose>
                                                            <c:when test="${ wao.progress == 2}">
                                                                <c:if test="${wao.state == 0}">
                                                                    审核拒绝
                                                                </c:if>
                                                                <c:if test="${wao.state == 1}">
                                                                    审核通过
                                                                </c:if>
                                                            </c:when>
                                                            <c:when test="${ wao.progress == 3}">
                                                                <c:if test="${wao.state == 0}">
                                                                    提出异议，再次提交申请
                                                                </c:if>
                                                                <c:if test="${wao.state == 1}">
                                                                    确认通过
                                                                </c:if>
                                                            </c:when>
                                                            <c:when test="${ wao.progress == 4}">
                                                                <c:if test="${wao.state == 0}">
                                                                    未处理
                                                                </c:if>
                                                                <c:if test="${wao.state == 1}">
                                                                    已打款，请注意查收
                                                                </c:if>
                                                            </c:when>
                                                        </c:choose>

                                                        </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                            <c:if test="${wao.progress == 2 && wao.state == 1}">
                                                                <label class="search-form-lable"><strong>尾款金额：</strong></label>
                                                                <span class="layui-input-inline">
                                                             <fmt:formatNumber pattern="0.00" value="${wao.payment}"/>元
                                                                </span>
                                                            </c:if>
                                                        </div>
                                                        <c:if test="${wao.progress == 2 || (wao.progress == 3 && wao.state == 0)}">
                                                            <div class="tc">
                                                                <label class="search-form-lable"><strong>备注：</strong></label>
                                                                <div class="layui-input-inline">
                                                                        ${wao.noteMessage}
                                                                </div>
                                                            </div>
                                                        </c:if>
                                                        <c:if test="${wao.progress == 2 || wao.progress == 3 }">
                                                            <c:if test="${wao.accessoryUrl !=null && wao.accessoryUrl!=''}">
                                                                <div class="tc">
                                                                    <label class="search-form-lable"><strong>附件：</strong></label>
                                                                    <div class="layui-input-inline">
                                                                        <a target="_blank" style="color: green" href="${wao.accessoryUrl}">下载附件</a>
                                                                    </div>
                                                                </div>
                                                            </c:if>
                                                        </c:if>
                                                    </c:if>
                                                </c:if>
                                            </td>
                                            <c:if test="${st.last}">

                                                <c:choose>
                                                    <c:when test="${ wao.progress == 3}">
                                                        <td colspan="2">
                                                            <div class="tc">
                                                                <div class="layui-input-inline">
                                                                    <c:if test="${ wao.state != 1}">
                                                                        <a class="layui-btn layui-btn-danger"
                                                                           href="javascript:check('确认要审核通过吗？','${wao.id}','${wao.wId}', 3,1)">确认通过</a>
                                                                    </c:if>
                                                                    <a class="layui-btn layui-btn-danger"
                                                                       href="javascript:check('确认要审核拒绝吗？','${wao.id}','${wao.wId}', 3,0)">再次申请</a>

                                                                </div>
                                                            </div>
                                                        </td>
                                                    </c:when>
                                                </c:choose>

                                            </c:if>
                                        </tr>
                                        <c:if test="${!st.last}">
                                            <tr>
                                                <td colspan="6" style="font-color:green;">
                                                    <div class="f18 tc">|</div>
                                                    <div class="f18 tc">|</div>
                                                    <div class="f18 tc">|</div>
                                                    <div class="f18 tc">V</div>
                                                </td>
                                            </tr>
                                        </c:if>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item"></div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>


    <div id="refusedittailParagraphDiv" style="padding: 0px 10px">
        <div>
            <form id="refusedittailParagraphForm" class="layui-form mt20" method="post"
                  action="${ctx}/moneyManagement/tailParagraph/editTailParagraph.do">
                <input type="hidden" name="id" value=""/>
                <input type="hidden" name="wId" value=""/>
                <input type="hidden" name="progress" value="">
                <input type="hidden" name="state" value="">
                <table class="layui-table" lay-skin="nob">
                    <tbody>
                    <tr>
                        <td>
                            <label class="layui-form-label">备注<span style="color: red;">*</span></label>
                            <div class="layui-input-block">
                            <textarea name="noteMessage" style="width: 250px;" placeholder="请填写备注"
                                      class="layui-textarea"></textarea>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="layui-form-label">添加附件<span style="color: red;">*</span></label>
                            <div class="cover-content">
                                <input type="hidden" id="accessoryUrl" name="accessoryUrl" class="layui-input" value=""/>
                                <div class="u-single-upload">
                                    <input type="file" class="u-single-file" id="accessory" name="accessory">
                                    <span class="u-single-upload-icon">上传附件</span>
                                </div>
                                <div class="file-name"></div>
                                <div class="upload-desc">请上传5张活动现场照片，至少包含1张大合影</div>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript" src="${ctxStatic}/cos-js-sdk-v4-master/dist/cos-js-sdk-v4.js"></script>
<script type="text/javascript" src="${ctx}/script/upload/cosUploadUtil.js"></script>
<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript">
    var $paragraphForm = null;
    $(function () {
        $paragraphForm = $("#refusedittailParagraphDiv #refusedittailParagraphForm");

        var cosUtil = new CosUtil({
            mainFolder: "/withdrawalFile/",
            bucketType: 1,// 0: 图片, 1: 文件
            insertOnly: 0,//insertOnly==0 表示允许覆盖文件 1表示不允许
            onProgress: function (file, ret) {

            }
        }).init();

        txz.initHeader({
            nav: [{
                name: '资金管理',
                curr: true
            }, {
                name: '${event.name}'
            }, {
                name: '提现详情',
                curr: true
            }],
            info: '',
            btns: [{
                name: '返回',
                href: '${ctx}/moneyManagement/withdrawalInfo.do?eventId=${event.id}',
                icon: 'back'
            }]
        });

        //加载分页
        loadPageNew({
            elem: 'page_content',
            totalCount: '${page.totalCount}',
            limit: '${page.limit}',
            page: '${page.page}'
        });

        var loadIndex = null;
        $('#accessory').change(function () {
            var wpId = $paragraphForm.find("[name=id]").val();
            var files = document.getElementById("accessory").files;
            var newFiles = new Array(1);
            newFiles[0] = files[0];
            var fileName = files[0].name;

            if (fileName.lastIndexOf(".rar") < 0 && fileName.lastIndexOf(".zip") < 0) {
                util.layerMsgError("请正确上传.rar/.zip格式的附件");
                return;
            }
            loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });

            cosUtil.opt.mainFolder = cosUtil.opt.mainFolder + wpId + "/";

            cosUtil.opt.onSuccess = function (file, result) {
                uploadCert(newFiles);
            };
            cosUtil.opt.onFailure = function (file, result) {
                uploadCert(newFiles);
            };
            cosUtil.getFileStat(newFiles[0]);
        });

        function uploadCert(newFiles) {
            var loadIndex = top.layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            // 上传附件
            cosUtil.opt.onSuccess = function (file, result) {
                top.layer.close(loadIndex);
                console.log(result.data)
                $("#accessoryUrl").val(result.data.access_url);
                util.layerMsgSuccess("附件上传成功", function () {
                    $paragraphForm.find('.file-name').html('<a href="' + result.data.access_url + '">' + file.name + '</a>');
                });
                console.log(result);
            };
            cosUtil.opt.onFailure = function (file, result) {
                layer.close(loadIndex);
                util.layerMsgError("附件上传失败");
                console.log(result);
            }
            cosUtil.uploadFile(newFiles);
        }
    })


    function check(content, id, wid, progress, state) {

        if (state == 1) {
            var lock = false //默认未锁定
            layer.confirm(content, {
                icon: 3,
                title: '系统提示'
            }, function (index) {
                var loadIndex = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
                if (!lock) {
                    lock = true
                    $.post("${ctx}/moneyManagement/tailParagraph/editTailParagraph.do", {
                        id: id,
                        wId: wid,
                        progress: progress,
                        state: state,
                    }, function (data) {
                        layer.close(loadIndex);
                        setTimeout(function () {
                            if (data.success == true) {
                                util.layerAlertSuccess("已通过", function () {
                                    window.location.reload();
                                })
                            } else {
                                util.layerAlertError("通过失败")
                            }
                        }, 500);
                    })
                }
            });
        } else {

            $("#refusedittailParagraphDiv #refusedittailParagraphForm").show();
            $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=id]").val(id);
            $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=wId]").val(wid);
            $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=progress]").val(progress);
            $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=state]").val(state);
            var lock = false //默认未锁定
            layer.confirm('确定要再次申请提现吗？', {icon: 3, title: '审核通知'}, function (index) {
                layer.open({
                    type: 1,
                    area: ['460px', '430px'],
                    title: '审核',
                    content: $("#refusedittailParagraphDiv"),
                    btn: ['确定', '取消'],
                    yes: function () { // 确定按钮
                        var checkRemark = $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=noteMessage]").val();
                        if (checkRemark.trim() == '') {
                            layer.msg('请填写审核备注', {time: 2000, icon: 0, title: '系统提示'});
                            return;
                        }
                        var accessoryUrl = $paragraphForm.find("[name=accessoryUrl]").val();
                        if (accessoryUrl == '') {
                            util.layerMsgError('请上传附件');
                            return;
                        }
                        if (!lock) {
                            lock = true;
                            $.post($("#refusedittailParagraphDiv #refusedittailParagraphForm").attr('action'),
                                $("#refusedittailParagraphDiv #refusedittailParagraphForm").serialize(), function (res) {
                                    if (res.success) {
                                        layer.msg('再次申请提现成功', {title: '审核通知', icon: 1, time: 2000}, function () {
                                            window.location.reload();
                                        });
                                    } else {
                                        layer.msg(res.description, {title: '审核通知', icon: 2, time: 2000});
                                    }
                                });
                        }
                    },
                    btn2: function () {// 取消按钮


                        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=id]").val('');
                        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=wId]").val('');
                        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=progress]").val('');
                        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=state]").val('');

                        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=noteMessage]").val('');
                        $("#refusedittailParagraphDiv #refusedittailParagraphForm .file-name").html('');
                        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=accessory]").val('');
                        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=accessoryUrl]").val('');

                        layer.close(index);
                    }
                });
            });
        }
    }


    /**
     * 拒绝尾款提现
     * @param wId,progress,state
     */
    function refusedTailParagraph(id, wId, progress, state) {

        $("#refusedittailParagraphDiv #refusedittailParagraphForm").show();
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=id]").val(id);
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=wId]").val(wId);
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=progress]").val(progress);
        $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=state]").val(state);
        layer.confirm('确定要审核拒绝提现吗？', {icon: 3, title: '审核拒绝提示'}, function (index) {
            layer.open({
                type: 1,
                area: ['400px', '250px'],
                title: '审核',
                content: $("#refusedittailParagraphDiv"),
                btn: ['确定', '取消'],
                yes: function () { // 确定按钮
                    var checkRemark = $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=noteMessage]").val();
                    if (checkRemark.trim() == '') {
                        layer.msg('请填写审核备注', {time: 2000, icon: 0, title: '系统提示'});
                        return;
                    }
                    $.post($("#refusedittailParagraphDiv #refusedittailParagraphForm").attr('action'),
                        $("#refusedittailParagraphDiv #refusedittailParagraphForm").serialize(), function (res) {
                            if (res.success) {
                                layer.msg('审核拒绝成功', {title: '审核通知', icon: 1, time: 2000}, function () {
                                    window.location.reload();
                                });
                            } else {
                                layer.msg(res.description, {title: '审核通知', icon: 2, time: 2000});
                            }
                        });
                },
                btn2: function () {// 取消按钮
                    $("#refusedittailParagraphDiv #refusedittailParagraphForm [name=noteMessage]").val("");
                    layer.close(index);
                }
            });
        });

    }
</script>
</body>
</html>